<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>文件上传列表</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <h1>文件上传列表</h1>
    <table class="table table-bordered" id='tabletest'>
    </table>


    <a th:href="@{/upload}">上传页面</a>
    <a th:href="@{/userList/1}">用户页面</a>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    $(function () {
        var requestBody = {
            // 请求体数据
        };
        // 页面加载时请求表格数据
        $.post('/file/finduploadInfoList', requestBody, function (data) {
            var tableHtml = '<thead><tr><th>文件名</th><th>上传时间</th><th>操作</th></tr></thead><tbody>';

            for (var i = 0; i < data.data.length; i++) {
                tableHtml += '<tr><td>' + data.data[i].fileName + '</td><td>' + data.data[i].updateTime + '</td><td><button class="delete-btn" data-id="' + data.data[i].id + '">删除</button><button class="view-btn" data-id="' + data.data[i].id + '">查看</button></td></tr>';
            }

            tableHtml += '</tbody>';

            // 将 HTML 表格插入到页面中
            $("#tabletest").append(tableHtml)

            // 添加删除、查看和通过按钮的点击事件处理程序
            $('.delete-btn').click(function () {
                var id = $(this).data('id');
                // 发送删除请求
                console.log('id:',id);
                $.get('/file/deleteUploadRecordById/'+id, function () {
                    // 删除成功后刷新表格
                    console.log('id:',id);
                    location.reload();
                });
            });

            $('.view-btn').click(function () {
                var id = $(this).data('id');
                // 发送查看请求
                console.log('id:',id);
                window.location.href = '/uploadUser/' + id;
            })

        });
    });


</script>
</body>
</html>